<?php

class Application_Model_DbTable_Boleto extends Zend_Db_Table_Abstract
{

    protected $_name = 'boleto';
    protected $_primary = array('id');    
    protected $_dependentTables = array('Application_Model_DbTable_BoletoProduto');

    public function getNumeroBoleto($numero, $id = null)
    {
        if($id <> null)
          $where = "numero = $numero and id <> $id";
        else
          $where = "numero = $numero";

        $select = $this->select();
        $select->from($this, array('count(*) as amount'))->where($where);
        $rows = $this->fetchAll($select);

        return($rows[0]->amount);
    }

    public function getNumeroBoletoExcludId($numero, $id)
    {
        $select = $this->select();
        $select->from($this, array('count(*) as amount'))->where("numero = $numero and id <> $id");
        $rows = $this->fetchAll($select);

        return($rows[0]->amount);
    }

    public function insert(array $data) {
          parent::insert($data);
          return $this->getAdapter()->lastInsertId();
    }
}

